package com.dep.common;

import java.io.Serializable;

public class ResponseData<T> implements Serializable {
    private static final long serialVersionUID = 1671315861192936825L;
    /**
     * 返回码 not http响应码
     */
    private int codeId;
    /**
     * 返回码描述
     */
    private String codeDes;
    private T resData;

    public int getCodeId() {
        return codeId;
    }

    public void setCodeId(int codeId) {
        this.codeId = codeId;
    }

    public String getCodeDes() {
        return codeDes;
    }

    public void setCodeDes(String codeDes) {
        this.codeDes = codeDes;
    }

    public T getResData() {
        return resData;
    }

    public void setResData(T resData) {
        this.resData = resData;
    }

    public ResponseData(CodeIdEnum codeIdEnum) {
        this.codeId = codeIdEnum.getValue();
        this.codeDes = codeIdEnum.getName();
    }

    public ResponseData(CodeIdEnum codeIdEnum, T resData) {
        this.codeId = codeIdEnum.getValue();
        this.codeDes = codeIdEnum.getName();
        this.resData = resData;
    }
    public ResponseData(int codeId, String codeDes) {
        this.codeId = codeId;
        this.codeDes = codeDes;
    }
    public ResponseData() {
    }
    public static <T> ResponseData<T> success() {
        ResponseData<T> result = new ResponseData<T>();
        result.setCodeId(CodeIdEnum.Success.getValue());
        result.setCodeDes(CodeIdEnum.Success.getName());
        return result;
    }
    public static <T> ResponseData<T> success(T data) {
        ResponseData<T> result = new ResponseData<T>();
        result.setCodeId(CodeIdEnum.Success.getValue());
        result.setCodeDes(CodeIdEnum.Success.getName());
        result.setResData(data);
        return result;
    }
//    public static <T> ResponseData<T> success(String msg) {
//        ResponseData<T> result = new ResponseData<T>();
//        result.setCodeId(CodeIdEnum.Success.getValue());
//        result.setCodeDes(msg);
//        return result;
//    }
    public static <T> ResponseData<T> fail(String msg) {
        ResponseData<T> result = new ResponseData<T>();
        result.setCodeId(CodeIdEnum.FAILED.getValue());
        result.setCodeDes(msg);
        return result;
    }
    public static <T> ResponseData<T> fail() {
        ResponseData<T> result = new ResponseData<T>();
        result.setCodeId(CodeIdEnum.FAILED.getValue());
        result.setCodeDes(CodeIdEnum.FAILED.getName());
        return result;
    }
    public static <T> ResponseData<T> fail(CodeIdEnum codeIdEnum) {
        ResponseData<T> result = new ResponseData<T>();
        result.setCodeId(codeIdEnum.getValue());
        result.setCodeDes(codeIdEnum.getName());
        return result;
    }
    public static <T> ResponseData<T> fail(Integer codeId, String msg) {
        ResponseData<T> result = new ResponseData<T>();
        result.setCodeId(codeId);
        result.setCodeDes(msg);
        return result;
    }

    @Override
    public String toString() {
        return "ResponseData{" +
                "codeId=" + codeId +
                ", codeDes='" + codeDes + '\'' +
                ", resData=" + resData +
                '}';
    }
}
